module.exports = function (app,models,$,db,nm){
    app.get('/article',(req,res) => {
		var query = {
			pageSize:req.query.pageSize || 10,
			pageNum:req.query.pageNum || 1,
			unitId:req.unitId
		}
		// if(req.query.type) query.name = {$regex:req.query.type}
		models.article.list(query, ret => {
			res.send(ret)
		},{
			projection: {
				_id:1,
				type:1,
				img:1,
				title:1,
				digest:1,
				time:1,
				userId:1,
				content:1,
				hot:1,
				status:1
			}
		})
	})
	//获取文章详情
	app.get("/v1/articleInfo", (req, res) => {
		if (req.query._id) {
		  models.article.find(
			{ _id: req.query._id },
			(ret) => {
			  res.send(ret);
			}
		  );
		} else {
		  res.send({ errorMsg: "请传入_id" });
		}
	  });

    //新增
 app.post('/v1/article',(req,res) => {
     req.body.unitId = req.unitId
     models.article.insert(req.body, ret => {
         res.send(ret)
     })
 })

 //修改
 app.put('/v1/article',(req,res) => {
     models.article.update({_id:req.body._id},req.body, ret => {
         res.send(ret)
     })
 })

 //删除
 app.delete("/v1/article", (req, res) => {
    models.article.remove({ _id: req.query._id }, (ret) => {
      res.send(ret);
    });
  });
}